<?php
	class Mainmodel extends CI_Model{

		//分页
		public function page_list($start,$total) {
			$this->load->database();
			return $this->db->query("select * from user limit $start,$total")->result_array();
			//$query = $this->db->get('christian_books', $num, $offset);  
		}
		//获取全部用户
		public function get_user(){
			$this->load->database();
			$query = $this->db->get('user');
			return  $query->result_array();
		}
		//增加用户
		public function add_user($data){
			$this->load->database();
			$result = $this->db->insert("user",$data);
			return $result;
		}
		//用户名查询
		public function row_user($data){
			$this->load->database();
			$result = $this->db->query("select * from user where username='$data'")->result();
			return $result;
		}
		//模糊查询
		public function vague_user($data){
			$this->load->database();
			$result=$this->db->query("select * from user where username like '%".$data."%'");
			//result_array()  和row_array() 用法一定要记住  result_array()返回时全部数据  row_array()返回第一条数据
			return $result->result_array();
		}
		//用户id查询
		public function row_id($data){
			$this->load->database();
			$result = $this->db->query("select * from user where id='$data'");
			return $result->row_array();
		}
		//删除用户
		public function dele_user($data){
			$this->load->database();
			return $this->db->delete('user',array('id'=>$data));

		}
		//更新用户
		public function save_user($id,$datas){
			$this->load->database();
			// $query = $this->db->where(array('id'=>$id))->update('user',$datas);
			 $query = $this->db->update('user',$datas,array('id'=>$id));
        	return $query;
		}
	}
?>